package cn.lutu.lutuspringboot.config;

import com.github.houbb.sensitive.word.api.IWordAllow;
import com.github.houbb.sensitive.word.api.IWordDeny;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.support.allow.WordAllows;
import com.github.houbb.sensitive.word.support.deny.WordDenys;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class sensitiveWordConfig {
    // 设置系统默认敏感词
    SensitiveWordBs wordBs = SensitiveWordBs.newInstance()
            .wordDeny(WordDenys.system()) // 黑名单
            .wordAllow(WordAllows.system()) // 白名单
            .init();

    // 设置自定义敏感词
    SensitiveWordBs customWordBs = SensitiveWordBs.newInstance()
            .wordDeny(new IWordDeny() {
                @Override
                public List<String> deny() {
                    return null;
                }
            })
            .wordAllow(new IWordAllow() {
                @Override
                public List<String> allow() {
                    List<String> allow = new ArrayList<>();
                    allow.add("测试");
                    allow.add("测");
                    return allow;
                }
            })
            .init();

    // 设置多个敏感词，系统默认和自定义
    IWordDeny wordDeny = WordDenys.chains(WordDenys.system());
    IWordAllow wordAllow = WordAllows.chains(WordAllows.system(), new IWordAllow() {
        @Override
        public List<String> allow() {
            List<String> allow = new ArrayList<>();
            allow.add("测试");
            allow.add("测");
            return allow;
        }
    });
    SensitiveWordBs NewWordBs = SensitiveWordBs.newInstance()
            .wordDeny(wordDeny)
            .wordAllow(wordAllow)
            .init();

}
